package com.example.controller;

import com.example.service.BookMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/bookMenu")
public class BookMenuController {

    @Autowired
    private BookMenuService bookMenuService;

    /**
     * 书目数据导入数据库
     * @param originalPath
     * @return 字符串提示信息
     */
    @PutMapping("/importDatabase")
    public String importDatabase(String originalPath){
        return bookMenuService.addOrUpdateBookMenu(originalPath);
    }

    /**
     * 下载书目的图片
     * @param originalPath
     * @return 字符串提示信息
     * @throws Exception
     */
    @PutMapping("/downloadImage")
    public String downloadImage(String originalPath) throws Exception{
        return bookMenuService.downloadImage(originalPath);
    }

    /**
     * 统计书目在数据库中存在的数目
     * @param originalPath
     * @return 字符串提示信息
     */
    @GetMapping("/bookExistNum")
    public String countBookExistNum(String originalPath){
        return bookMenuService.countBookExistNum(originalPath);
    }

    /**
     * 穷举各出版社的isbn
     * @param originalPath
     * @return 字符串提示信息
     */
    @GetMapping("/exhaustion/isbn")
    public String exhaustionIsbn(String originalPath){
        return bookMenuService.exhaustionIsbn(originalPath);
    }

    /**
     * 根据作者和出版社找标签
     * @param dirPath
     * @return 字符串提示信息
     */
    @PutMapping("/findLabel/authorPublisher")
    public String findLabelByAuthorPublisher(String dirPath){
        return bookMenuService.findLabelByAuthorPublisher(dirPath);
    }
}
